﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Products.Enumerations;

namespace RiderShop.Mobile.Common.Component
{
    public class FormatProduct
    {
        /// <summary>
        /// 获取product image url
        /// </summary>
        public static string FormatProductImageUrl(ImageType size, object productId, object imageName)
        {
            string urlKy = string.Format("ProductManagement_ProductImage{0}", (int)size);
            if (imageName == null || imageName.ToString() == ProductBasicInfo.DefaultComingSoonImage)
            {
                urlKy = string.Format("ProductManagement_ProductImageComingSoon{0}", (int)size);
#if !SILVERLIGHT
                return FormatUrl(urlKy);
#endif

#if SILVERLIGHT
                return Common.Entity.Silverlight.Helper.CommonHelper.GetPageUrl(urlKy);
#endif

            }
            string prifx = ImageEntity.GetProductImagePrifx(productId.ToString());

#if !SILVERLIGHT
            return FormatUrl(urlKy, prifx, productId, imageName);
#endif

#if SILVERLIGHT
            var url = Common.Entity.Silverlight.Helper.CommonHelper.GetPageUrl(urlKy);
            return string.Format(url, prifx, productId, imageName);
#endif
        }

        public static string FormatUrl(string name, params object[] parameters)
        {
            string value = null;
            SiteUrl.UrlList.TryGetValue(name, out value);

            if (value != null)
            {
                var url = string.Empty;
                url = parameters == null ? value : string.Format(value, parameters);
                url = url.ToLower().Contains("http://") || url.ToLower().Contains("https://") ? url : Globals.ApplicationBase + url;
                return url;
            }
            throw new NullReferenceException("Not exist,Please check Url Key:" + name);
        }
    }
}
